﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Samurai.DAL;
using Samurai.Infrastructure;
using System.Windows.Input;

namespace Samurai.Client
{
    public class RefreshRepositoryCommand : ICommand
    {
        private readonly ObservableCollection<Repository> _repositoryLocations;

        public RefreshRepositoryCommand(ObservableCollection<Repository> repositoryLocations)
        {
            this._repositoryLocations = repositoryLocations;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            var repositoryLocations = Manager.Instance.GetRepositoryLocations();

            _repositoryLocations.Clear();

            foreach (var repositoryLocation in repositoryLocations)
            {
                _repositoryLocations.Add(repositoryLocation);
            }
        }
    }
}